package com.mfrs.demos;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;

import hk.cic.demointegrationapp.R;

public class EditAc extends Activity {
	public final static String USER_NAME = "USER_NAME";
	
	public static void start(Activity ac, int requestCode, String userName){
		Intent i = new Intent(ac, EditAc.class);
		i.putExtra(USER_NAME, userName);
		ac.startActivityForResult(i, requestCode);
	}

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.ac_edit);
		
		String userName = getIntent().getStringExtra(USER_NAME);
		if(userName == null){
			userName = "";
		}
		final EditText ed_name = (EditText)findViewById(R.id.ed_name);
		ed_name.setText(userName);
		
		findViewById(R.id.btn_save).setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				String user = ed_name.getText().toString().trim();
				if(user == null || user.equals("")){
					showToast("请输入用户姓名");
					return;
				}
				
				Intent i = new Intent();
				i.putExtra(USER_NAME, user);
				setResult(RESULT_OK, i);
				finish();
			}
		});
	}
	
	private void showToast(String msg){
		Toast.makeText(this, msg, Toast.LENGTH_SHORT).show();
	}
}